package com.yanqu.road.server.cmd.activity.washe;

import com.yanqu.road.entity.activity.washe.data.WasheBattleRecord;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.WasheProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.washe.WasheModule;
import com.yanqu.road.server.pb.WashePb;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;

@Cmd(code = GameProtocol.S_WASHE_GET_BATTLE_RECORD, desc = "")
public class WasheGetBattleRecordCmd extends AbstractCommand {

    private List<WasheBattleRecord> list;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        list = player.getModule(WasheModule.class).getRecordListByCmd();
    }

    @Override
    public void sendData(GamePlayer player) {
        WasheProto.WasheGetBattleRecordRespMsg.Builder builder = WasheProto.WasheGetBattleRecordRespMsg.newBuilder();
        for (WasheBattleRecord record : list) {
            builder.addList(WashePb.parseWasheBattleRecordMsg(record));
        }
        player.sendPacket(ClientProtocol.U_WASHE_GET_BATTLE_RECORD, builder);
    }
}
